<?php

namespace frontend\modules\h5\controllers;

use Yii;
use frontend\components\Controller;
use frontend\modules\h5\models\OrangeOrderForm;

/**
 * 橙子兑换商城首页
 */
class OrangeOrderController extends Controller {

    /**
     * @inheritdoc
     */
    protected function rules() {
        return [
            [
                'allow' => true,
                'roles' => ['@'],
            ],
        ];
    }

    /**
     * @inheritdoc
     */
    protected function verbs() {
        return [
            '*' => ['POST'],
        ];
    }

    /**
     * 橙子商品下单
     * @return string
     */
    public function actionCreate() {
        $model = new OrangeOrderForm();
        $post = Yii::$app->request->post();
        if (!$model->load($post, '')) {
            parent::warning('订单创建时提交的数据未加载成功');
        }
        $model->user_id = $this->user->id;
        $data = $model->save();
        $data['post'] = $post;
        return $data;
    }

}
